package cn.duxiaod.demo.proxy.cglibDynamicProxy;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class DebugMethodInterceptor implements MethodInterceptor {
    /**
     *
     * @param o                 被代理的对象
     * @param method            拦截的方法（需要增强的代理方法）
     * @param objects           方法入参
     * @param methodProxy       用于调用原始方法
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("before method " + method.getName());
        Object result = methodProxy.invokeSuper(o, objects);
        System.out.println("after method " + method.getName());
        return result;
    }
}
